<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加商品</title>
    <link rel="stylesheet" href="public/layui/css/layui.css">
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
        }
    </style>
</head>

<body>
    <form class="layui-form layui-form-pane layui-padding-3" lay-filter="edit" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-inline">
                <input type="text" name="good_name" autocomplete="off" placeholder="请输入商品名称" lay-verify="required"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品类型</label>
            <div class="layui-input-inline">
                <select name="type" lay-verify="required" id="type">
                    <option value="">请选择商品类型</option>
                    <option value="2">会员商品</option>
                    <option value="3">卡密商品</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所需积分</label>
            <div class="layui-input-inline">
                <input type="number" lay-verify="required" lay-affix="number" name="score" placeholder="积分" step="10"
                    min="0" class="layui-input" value="0">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">vip时长数量</label>
            <div class="layui-input-inline">
                <input type="number" lay-affix="number" name="vip_count" placeholder="对应vip时长数量" step="1" min="0"
                    class="layui-input" value="1">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会员时长</label>
            <div class="layui-input-inline">
                <select name="vip_type">
                    <option value="">请选择会员时长</option>
                    <option value="1" selected>天</option>
                    <option value="2">月</option>
                    <option value="3">年</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">卡密类型</label>
            <div class="layui-input-inline">
                <select name="fake_type" lay-verify="required">
                    <option value="0">请选择卡密类型</option>
                    <option value="1">普通卡密</option>
                </select>
            </div>
           
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">库存</label>
            <div class="layui-input-inline">
                <input type="number" lay-affix="number" name="stock" placeholder="库存" step="1" min="0"
                    class="layui-input" value="1">
            </div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label">商品状态</label>
            <div class="layui-input-block">
                <input type="checkbox" checked name="status" lay-skin="switch" lay-filter="switchTest" title="上架">
            </div>
        </div>
        <div>
            <span class="layui-font-orange">PS ： 如果没有选择卡密商品（可忽略选项，直接添加）</span>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn" lay-submit lay-filter="add">添加</button>
        </div>
    </form>
    <script src="./public/layui/layui.js"></script>
    <script>
        layui.use(function () {
            var form = layui.form
            var $ = layui.$
            form.on('submit(add)', function (data) {
                field = data.field
                $.post('?p=index&c=good&a=doAdd', field, (res) => {
                    if (res.code == 200) {
                        layer.msg('添加成功')
                    } else {
                        layer.msg(res.msg)
                    }
                })
                return false
            })
        })
    </script>
</body>

</html>